﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ORS.OrderRobot.ServiceContracts;
using ORS.OrderRobot.ServiceContracts.Dtos;
using ORS.OrderRobot.ServiceContracts.Dtos.Api;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace ORS.OrderRobot.WebApp.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    //[Authorize]
    public class ManagerController : Controller
    {
        private readonly IAccountService _accountService;
        private readonly IAccountLoginService _accountLoginService;
        private readonly IProductMointerLogService _productMointerLogService;
        private readonly IAccountOrderService _accountOrderService; 
        public ManagerController(
            IAccountService accountService,
            IAccountLoginService accountLoginService,
            IProductMointerLogService productMointerLogService,
            IAccountOrderService accountOrderService)
        {
            _accountService = accountService;
            _accountLoginService = accountLoginService;
            _accountOrderService = accountOrderService;
            _productMointerLogService = productMointerLogService;

        }
        /// <summary>
        /// 添加或更新账号池信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut("account-createOrUpdate")]
        public async Task createOrUpdate([FromBody] AccountInput input)
        {
            await _accountService.CreateUpdateAsync(input);
        }
        /// <summary>
        /// 取得所有活动用户
        /// </summary>
        /// <param name="isActive">是否活动状态的</param>
        /// <returns></returns>
        [HttpGet("account-list")]
        public async Task<List<AccountDto>> GetAllActiveAccountAsync(bool isActive = true)
        {
            var list = await _accountService.GetAllAsync(new GetAllInput { IsActive = true,LoadBoardingFromDb = true });
            return list;
        }
        /// <summary>
        /// 设置账号状态
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut("account-setStatus")]
        public async Task UpdateAccountsStatus(AccountStatusInput input)
        {
            await _accountService.SetActiveStatusAsync(input);
        }
        /// <summary>
        /// 三方账号登录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("thirdpart-login")]
        public async Task<LoginResultInfo?> ThirdPartLogin(AccountBasicInput input)
        {
            var data = await _accountLoginService.LoginAsync(input.Email, input.Password);
            return data;
        }
        /// <summary>
        /// 同步账号基本信息到三方服务器
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("thirdpart-sync")]
        public async Task ThirdPartSync(AccountBasicInput input)
        {
            await _accountService.SyncProfileToThridPart(input);
        }
        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("getProducts")]
        public async Task<List<ProductMointerLogDto>> GetProducts(GetProductInput input)
        {
            var data = await _productMointerLogService.GetList(input);
            return data;
        }
        /// <summary>
        /// 获取订单列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("getOrders")]
        public async Task<List<OrderDto>> GetOrderList(GetOrderInput input)
        {
            var data = await _accountOrderService.GetList(input);
            return data;
        }
    }
}

